/*
 * This file is part of TradeHelper library.
 *
 * TradeHelper library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TradeHelper library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TradeHelper library.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.rag.assistants;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * User: mgarin Date: 13.06.12 Time: 15:35
 */

public class DataZipper
{
    public static void zipData ()
    {
        // Create a buffer for reading the files
        byte[] buf = new byte[ 1024 ];

        try
        {
            // Create the ZIP file
            String target = "remote/data.zip";
            ZipOutputStream out = new ZipOutputStream ( new FileOutputStream ( target ) );

            // Compress the files
            FileInputStream in = new FileInputStream ( "remote/data.xml" );

            // Add ZIP entry to output stream.
            out.putNextEntry ( new ZipEntry ( "data.xml" ) );

            // Transfer bytes from the file to the ZIP file
            int len;
            while ( ( len = in.read ( buf ) ) > 0 )
            {
                out.write ( buf, 0, len );
            }

            // Complete the entry
            out.closeEntry ();
            in.close ();

            // Complete the ZIP file
            out.close ();
        }
        catch ( IOException e )
        {
            e.printStackTrace ();
        }
    }
}